<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <title>修改密码</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" href="/statics/layui/css/layui.css" media="all">
  <style>
      .layui-elem-quote{
        border-left: 5px solid #3b85c8;
      }
    </style>
</head>

<body>

  <fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
    <legend>修改登入密码</legend>
  </fieldset>
  <blockquote class="layui-elem-quote">注意：密码修改成功后您需要重新登录系统！</blockquote>
  <form class="layui-form" action="">
    <div class="layui-form-item">
      <label class="layui-form-label">原密码</label>
      <div class="layui-input-inline">
        <input type="password" name="oldPassword" lay-verify="required|pass" placeholder="请输入密码" autocomplete="off" class="layui-input" maxlength="12" />
      </div>
      <div class="layui-form-mid layui-word-aux">请填写6到12位密码</div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">新密码</label>
      <div class="layui-input-inline">
        <input type="password" name="newPassword" lay-verify="required|pass" placeholder="请输入新密码" autocomplete="off" class="layui-input" maxlength="12" />
      </div>
      <div class="layui-form-mid layui-word-aux">请填写6到12位密码</div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">确认密码</label>
      <div class="layui-input-inline">
        <input type="password" name="surePassword" lay-verify="required|pass" placeholder="请输入确认密码" autocomplete="off" class="layui-input" maxlength="12" />
      </div>
      <div class="layui-form-mid layui-word-aux">请填写6到12位密码</div>
    </div>
    <div class="layui-form-item">
      <div class="layui-input-block">
        <button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="demo1">修改密码</button>
      </div>
    </div>
  </form>
  <br/>
  <fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
      <legend>修改交易密码</legend>
    </fieldset>
    <form class="layui-form" action="">
      <div class="layui-form-item">
        <label class="layui-form-label">原密码</label>
        <div class="layui-input-inline">
          <input type="password" name="oldPassword" lay-verify="required|dealpass" placeholder="请输入密码" autocomplete="off" class="layui-input" maxlength="6" />
        </div>
        <div class="layui-form-mid layui-word-aux">请填写6位数字</div>
      </div>
      <div class="layui-form-item">
        <label class="layui-form-label">新密码</label>
        <div class="layui-input-inline">
          <input type="password" name="newPassword" lay-verify="required|dealpass" placeholder="请输入新密码" autocomplete="off" class="layui-input" maxlength="6" />
        </div>
        <div class="layui-form-mid layui-word-aux">请填写6位数字</div>
      </div>
      <div class="layui-form-item">
        <label class="layui-form-label">确认密码</label>
        <div class="layui-input-inline">
          <input type="password" name="surePassword" lay-verify="required|dealpass" placeholder="请输入确认密码" autocomplete="off" class="layui-input" maxlength="6" />
        </div>
        <div class="layui-form-mid layui-word-aux">请填写6位数字</div>
      </div>
      <div class="layui-form-item">
        <div class="layui-input-block">
          <button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="demo2">修改密码</button>
        </div>
      </div>
    </form>

  <script src="/statics/layui/layui.js" charset="utf-8"></script>
  <script type="text/javascript" src="../js/jquery-1.11.0.min.js"></script>
  <script type="text/javascript" src="../js/config.js"></script>
  <script type="text/javascript" src="../js/utils.js"></script>
  <script>
    layui.use(['form'], function () {
      var form = layui.form, layer = layui.layer;

      //自定义验证规则
      form.verify({
        pass: [/(.+){6,12}$/, '密码必须6到12位'],
        dealpass: [/^\d{6}$/, '交易密码必须6位数字']
      });

      //监听提交
      form.on('submit(demo1)', function (data) {
        var json = data.field;
        if (json.newPassword != json.surePassword) {
          layer.alert("两次输入的密码不一致，请重新输入", { title: '出错了', icon: 5 });
        } else {
          var url = Config.WEB_SERVER_API + Config.URI.MODIFY_PASSWORD;
          HttpUtils.httpPost(url, json, function (result, success) {
            if (success) {
              layer.alert('修改成功，请重新登录！', { title: '提示' }, function (index) {
                window.top.location.reload();
              });
            } else {
              layer.alert(result.resultMsg, { title: '出错了', icon: 5 });
            }
          });
        }
        return false;
      });

      //监听提交
      form.on('submit(demo2)', function (data) {
        var json = data.field;
        if (json.newPassword != json.surePassword) {
          layer.alert("两次输入的密码不一致，请重新输入", { title: '出错了', icon: 5 });
        } else {
          var url = Config.WEB_SERVER_API + Config.URI.MODIFY_DEAL_PASSWORD;
          HttpUtils.httpPost(url, json, function (result, success) {
            if (success) {
              layer.alert('交易密码修改成功！', { title: '提示' }, function (index) {
                window.location.reload();
              });
            } else {
              layer.alert(result.resultMsg, { title: '出错了', icon: 5 });
            }
          });
        }
        return false;
      });
    });
  </script>

</body>

</html>